package com.onepunch.common;

/**
 * @Author: yx
 * @Date: 2025/10/30 05:48
 * @Description:
 **/

import lombok.Data;

/**
 * @projectName: onePunch
 * @package: com.onepunch.common
 * @className: Result
 * @author: yx
 * @description:
 * @date: 2025/10/30 05:48
 * @version: 1.0
 */
@Data
public class Result {
    // 0成功，1失败
    private int code;
    private String msg;
    private Object data;

    public static Result success(int code, String msg, Object data) {
        Result result = new Result();
        result.code = 0;
        result.msg = "success";
        return result;
    }

    // 成功时返回数据
    public static Result success(Object data) {
        Result result = new Result();
        result.code = 0;
        result.msg = "success";
        result.data = data;
        return result;
    }

    //  失败（默认错误码1）
    public static Result error(String msg) {
        Result result = new Result();
        result.code = 1;
        result.msg = msg;
        return result;
    }

    //  失败（自定义错误码和信息）
    public static Result error(int code, String message) {
        Result result = new Result();
        result.code = code;
        result.msg = message;
        return result;
    }


}
